package org.ouwh.fw.db;

import java.sql.Connection;

class ConnectionWrapper {
	private JdbcPool pool;
	private Connection connection;
	private String jdbcURL;
	private String jdbcDriver;
	private long returnTime;
	private Thread ownerThread;
	private StackTraceElement[] ownerThreadStack;

	ConnectionWrapper(Connection connection, JdbcPool pool) {
		this.connection = connection;
		this.pool = pool;
	}

	public String getJdbcURL() {
		return jdbcURL;
	}

	public String getJdbcDriver() {
		return jdbcDriver;
	}

	public void setJdbcURL(String jdbcURL) {
		this.jdbcURL = jdbcURL;
	}

	public void setJdbcDriver(String jdbcDriver) {
		this.jdbcDriver = jdbcDriver;
	}

	public long getReturnTime() {
		return returnTime;
	}

	public Connection getRawConnection() {
		return connection;
	}

	public ConnectionProxy newProxy() {
		return new ConnectionProxy(this);
	}

	public void release() {
		returnTime = System.currentTimeMillis();
		pool.releaseConnection(this);
	}

	public void markOwnerThread() {
		ownerThread = Thread.currentThread();
		ownerThreadStack = ownerThread.getStackTrace();
	}

	public Thread getOwnerThread() {
		return ownerThread;
	}

	public StackTraceElement[] getOwnerThreadStack() {
		return ownerThreadStack.clone();
	}

}
